package xyz.xtt.admin.interceptors;

import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import xyz.xtt.admin.constants.ErrorMessage;
import xyz.xtt.admin.exception.ChainException;
import xyz.xtt.admin.utils.JwtUtil;
import xyz.xtt.admin.utils.ThreadLocalUtil;

@Component
public class LoginInterceptor implements HandlerInterceptor {
	public static final String AUTHORIZATION = "Authorization";

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//		String requestURI = request.getRequestURI();
//		String token = request.getHeader(AUTHORIZATION);
//		try {
//			Map<String, Object> claims = JwtUtil.parseToken(token);
//			ThreadLocalUtil.set(claims);
//		} catch (Exception e) {
//			// response.setStatus(401);
//			throw new ChainException(ErrorMessage.ADMIN_LOGIN_TYPE_ERR);
//		}

		return true;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		ThreadLocalUtil.remove();
	}

}
